<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('user_roles', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('remark')->nullable();
            $table->string('type');
            $table->string('role_keys')->nullable();
//            $table->string('parent_role_id')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

        //创建锁定的各个等级
        foreach (\App\Enums\UserType::cases() as $type) {
            if ($type == \App\Enums\UserType::System) {
                continue;
            }

            \App\Models\UserRole::create([
                'name' => $type->label(),
                'type' => $type->value,
                'remark' => $type->label(),
            ]);
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('user_roles');
    }
};
